package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;
import com.localjoycommunity.cpdj.project.system.domain.LeagueBranch;
import com.localjoycommunity.cpdj.project.system.service.ILeagueBranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 团支部Controller
 *
 * @author aqie
 * @date 2020-11-04
 */
@RestController
@RequestMapping("/system/league_branch")
public class LeagueBranchController extends BaseController {
    @Autowired
    private ILeagueBranchService leagueBranchService;

    /**
     * 查询团支部列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LeagueBranch leagueBranch) {
        startPage();
        List<LeagueBranch> list = leagueBranchService.selectLeagueBranchList(leagueBranch);
        return getDataTable(list);
    }

    /**
     * 导出团支部列表
     */
    @Log(title = "团支部", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LeagueBranch leagueBranch) {
        List<LeagueBranch> list = leagueBranchService.selectLeagueBranchList(leagueBranch);
        ExcelUtil<LeagueBranch> util = new ExcelUtil<LeagueBranch>(LeagueBranch.class);
        return util.exportExcel(list, "league_branch");
    }

    /**
     * 获取团支部详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(leagueBranchService.selectLeagueBranchById(id));
    }

    /**
     * 新增团支部
     */
    @Log(title = "团支部", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeagueBranch leagueBranch) {
        return toAjax(leagueBranchService.insertLeagueBranch(leagueBranch));
    }

    /**
     * 修改团支部
     */
    @Log(title = "团支部", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeagueBranch leagueBranch) {
        return toAjax(leagueBranchService.updateLeagueBranch(leagueBranch));
    }

    /**
     * 删除团支部
     */
    @Log(title = "团支部", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(leagueBranchService.deleteLeagueBranchByIds(ids));
    }
}
